import QtQuick 2.15

Rectangle {
    id: rootItem
    color: "#333333"

    property bool slidingState: true // 状态切换 ("visible" 或 "hidden")

    // 动画相关
    Behavior on y {
        NumberAnimation {
            duration: 300 // 动画持续时间
            easing.type: Easing.InOutCubic

            onFinished: {
                if(rootItem.slidingState)
                    rootItem.visible = false
            }

            onStarted: {
                if(!rootItem.slidingState)
                    rootItem.visible = true
            }
        }
    }

    Behavior on x {
        NumberAnimation {
            duration: 300 // 动画持续时间
            easing.type: Easing.InOutCubic
        }
    }

    function hide(){
        slidingState = false
    }

    function show() {
        slidingState = true
    }
}
